﻿<%@ WebHandler Language="C#" Class="regist" %>

using System;
using System.Web;

public class regist : IHttpHandler
{
    result result = new result();
    string str = "";
    sqlhelp sql = new sqlhelp();

    public void ProcessRequest(HttpContext context)
    {

        string Id = Guid.NewGuid().ToString();//商铺id
        string Name = "";//商铺名字
        string Tel = "";//手机号
        string UserName = "";//用户名
        string PassWord = "";//密码
        int AuthorizeFlg = 0;//授权标志
        string Avatar = Guid.NewGuid().ToString();//商城图标
        string Address = "";//公司地址
        string CreateTime = DateTime.Now.ToString();//录入时间
        int Enable = 1;//是否有效
        if (context.Request["Name"] != null)
        {
            Name = context.Request["Name"].ToString();
        }
        else
        {
            result.code = "0";
            result.msg = "未传递商铺名字参数";
            unit.send(context, result);
            return;
        }
        if (context.Request["Tel"] != null)
        {
            Tel = context.Request["Tel"].ToString();
        }
        else
        {
            result.code = "0";
            result.msg = "未传递手机号参数";
            unit.send(context, result);
            return;
        }
        if (context.Request["UserName"] != null)
        {
            UserName = context.Request["UserName"].ToString();
        }
        else
        {
            result.code = "0";
            result.msg = "未传递用户名参数";
            unit.send(context, result);
            return;
        }
        if (context.Request["PassWord"] != null)
        {
            PassWord = context.Request["PassWord"].ToString();
        }
        else
        {
            result.code = "0";
            result.msg = "未传递密码参数";
            unit.send(context, result);
            return;
        }

        if (context.Request["Avatar"] != null)
        {
            Avatar = context.Request["Avatar"].ToString();
        }
        else
        {
            result.code = "0";
            result.msg = "未传递商城图标参数";
            unit.send(context, result);
            return;
        }

        if (context.Request["Address"] != null)
        {
            Address = context.Request["Address"].ToString();
        }
        else
        {
            result.code = "0";
            result.msg = "未传递公司地址参数";
            unit.send(context, result);
            return;
        }

        string code = unit.initCode();

        if (Avatar != "")
        {
            Guid avatarId = Guid.NewGuid();
            str = "insert into SYS_Image(Id,Linkid,Path,CreateTime,Enable) values('" + avatarId + "','" + Id + "','" + Avatar + "','" + DateTime.Now.ToString() + "',1)";
            sql.ExecuteNonQuery(str);

            str = "insert into SYS_Store(Id,Code,Name,Tel,UserName,PassWord,AuthorizeFlg,Avatar,Address,CreateTime,Enable) values('" + Id + "','" + code + "','" + Name + "','" + Tel + "','" + UserName + "','" + PassWord + "'," + AuthorizeFlg + ",'" + avatarId + "','" + Address + "','" + CreateTime + "'," + Enable + ")";
            if (sql.ExecuteNonQuery(str) > 0)
            {
                string comId = Guid.NewGuid().ToString();//	uniqueidentifier	0	id

                str = "insert into SYS_CompanyWeb(Id,StoreId,CreateTime,Enable) values('" + comId + "','" + Id + "'," + CreateTime + "," + Enable + ")";
                sql.ExecuteNonQuery(str);
                result.code = "1";
                result.msg = "";
                unit.send(context, result);
            }
            else
            {
                result.code = "0";
                result.msg = "注册失败";
                unit.send(context, result);
            }
        }

    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}